Skip to content

[PR] fix(persist): #7670 warn on cold load when the [acp-drift] fold-coverage alert is off - #7673

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-11-24_fold-latch-cold-load-warn
Open

ranxianglei wants to merge 1 commit into
masterfrom
2026-11-24_fold-latch-cold-load-warn

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

The pendingFoldUsage latch is intentionally NOT restored on cold load (src/persist.ts:4308-4313, #2129 triage), so the [acp-drift] fold-coverage alert (the foldCoveredBefore gate in all four prepare-* files) is off on the first post-load request — the exact round that could destroy the fold (client resends mutated/truncated history losing covered ids → block silently active:false, no log).

This is Option B from #7670 — the no-decision-dependency stopgap: buildSession now warns whenever a session with active fold blocks is loaded, so the operator knows the alert is off. The latch restoration behavior is unchanged (no false-positive risk; the existing #2129 comment's concern about mislabeling an unrelated post-reload report is untouched).

Why Option B now

  • No behavior change — purely additive observability. The alert stays off (same as today); the operator just gets a loud warn instead of silence.
  • Catches every load path — the log lives in buildSession (the single choke point for all 16 load paths: cold load, fork, recovery, unified-store, legacy).
  • The proper fix (Option C: re-derive the latch) is a design decision — it changes the alert's firing semantics and needs owner approval on the false-positive-vs-coverage tradeoff. That is raised in-thread as a decision request, not bundled here.

Behavior change

None. The latch is still not restored. The only new output is a warn log line on cold load of a session with active fold blocks:

[warn] [persist] <id>: loaded N active fold block(s) with pendingFoldUsage latch NOT restored — the [acp-drift] fold-coverage alert is off on the first post-load request; a fold destroyed in that round will not be logged (#7670)

Test

tests/persist-fold-latch-warn.test.ts pins both directions (Gate Test Discipline #3617):

  • Positive: session with an active fold block ⇒ warn fires, names the session id + block count.
  • Negative 1: blockless session ⇒ warn stays silent.
  • Negative 2: session whose blocks are all inactive ⇒ warn stays silent.

Labels

  • bug (observability gap in a critical path — the alert that should catch fold destruction is silently off)
  • p2 (the tool is still usable; the gap is that a specific failure mode goes unlogged, not that the tool is broken)
  • scope/kernel (fold-ledger / context-management core logic)

Closes #7670

…age alert is off

The pendingFoldUsage latch is intentionally NOT restored on cold load
(#2129 triage), so the [acp-drift] fold-coverage alert is off on the first
post-load request — the exact round that could destroy the fold (client
resends mutated/truncated history losing covered ids → block silently
active:false, no log).

buildSession now warns whenever a session with active fold blocks is loaded,
so the operator knows the alert is off. Latch restoration behavior is
unchanged (Option B stopgap from #7670; the proper fix — re-deriving the
latch — is a separate design decision).

Test: tests/persist-fold-latch-warn.test.ts pins both directions (active
blocks ⇒ warn fires; no/inactive blocks ⇒ warn stays silent).
@ranxianglei ranxianglei added bug Something isn't working p2 scope/kernel labels Nov 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-24_fold-latch-cold-load-warn (46ce5ec)

Latest build — install this exact version

npm install -g billion-context@0.0.11819-pr.7673.4e2f31a

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
46ce5ec billion-context@0.0.11819-pr.7673.4e2f31a build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr7673.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix(persist): #7670 warn on cold load when the [acp-drift] fold-coverage alert is off [PR] fix(persist): #7670 warn on cold load when the [acp-drift] fold-coverage alert is off Nov 24, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷
(ai: qwen/qwen3.8-27b)

Duplicate screening: Not a duplicate — #7673 is the only open PR for the #7669 fold-coverage-alert gap (no parallel PR found).

Review of PR #7673 — Option B stopgap for #7669: warn on cold load when the [acp-drift] fold-coverage alert is off.

Code — correct. The pendingFoldUsage latch is indeed intentionally NOT restored on cold load (src/persist.ts:4308-4313), so foldCoveredBefore is null on the first post-load request in all four prepare-* files (prepare-anthropic.ts:368, prepare-openai.ts:330, prepare-responses.ts:364, prepare-google.ts:201) → the alert is off exactly in the round that could destroy the fold. The warn sits in buildSession (the single choke point — every load/recovery path goes through it), fires only when active fold blocks > 0, and reuses the existing loggerLog + .filter((b) => b.active) pattern (already at src/persist.ts:1812). Purely additive, no behavior change.

Tests — real teeth (Gate Test Discipline #3617, both directions): positive (active block ⇒ warn fires, names the session id + "1 active fold block", and asserts the latch is undefined), negative-1 (blockless ⇒ silent), negative-2 (all-inactive ⇒ silent). All referenced APIs exist (setLogCapture at src/logger.ts:206, loadSync/writeNow/flushAll/closeQuietly on SessionStore, createInitialState, rmrf, CompressionBlock).

CI — green. Final run 15:11–15:19Z: all 12 test shards (ubuntu/windows × 22/24) + gates = success, 0 failures. The 38 cancelled runs are the superseded 15:04Z invocation (concurrency cancellation), not failures.

🔴 BLOCKING — wrong issue reference (must fix before merge): The title, body, and commit message all cite #7670, but the real source issue is GitHub #7669. GitHub #7670 is a different PR ("fix: log mid-stream abort origin"). Root cause: #7669 was mirrored from ework issue #7670 (see the _Mirrored from ework issue #7670_ footer in #7669's body) — the mirror number #7670 was written into the GitHub PR instead of the GitHub number #7669. Consequence: the body's Closes #7670 would close the wrong PR (the mid-stream abort PR) on merge. Fix: change #7670 → #7669 in the title, the body (Closes #7669), and the commit message. (I can't edit the PR title/body — that's owner/author territory — so this one needs your hand.)

Minor — behind master: the branch is behind current master; update/rebase before merge so CI re-runs on the current base.

Labels (recommended; the mirror shim doesn't expose the label endpoint, so I couldn't apply them programmatically): bug, p2, scope/kernel.


8问(PR #7673 审核结论)

  1. 是什么问题:pendingFoldUsage 闩在冷加载时有意不恢复(Restart loses measurement state: buildSession() omits stats fields buildRecord() persists (k̂, usage anchor, baseline origin, localInputEstimate) #2129),[acp-drift] fold-coverage 告警在重载后第一轮(恰是能摧毁 fold 的那轮)关闭——fold 被静默 active:false 且无日志。本 PR 是 [Drive-by] pendingFoldUsage latch not restored on cold load — alert off in the round that could destroy the fold (#7261 Finding C) #7669 的 Option B 止血:加载带活跃 fold 块的会话时打一条 warn,让运维知道告警此刻是关的。
  2. 什么原因导致的:闩在 buildSession 的 stats 白名单里被刻意排除(src/persist.ts:4308-4313 注释),重载后 pendingFoldUsage 为 undefined,四个 prepare-* 的 foldCoveredBefore 门因此为 null,告警不触发。
  3. 影响范围与严重程度:纯可观测性缺口——工具仍可用,只是「关键轮 fold 被毁」这一失效模式无日志。p2(非数据丢失/缓存泄露,缺的是一条日志)。
  4. 怎么修复的:在 buildSession(所有加载/恢复路径的唯一咽喉)末尾数活跃 fold 块,>0 即 warn,点名 session id + 块数;不改恢复行为(无新增误报风险)。
  5. 是否有回归问题:无。纯追加一条日志,不触碰任何既有行为/阈值/时序/输出格式。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:无。Option B 是止血;根治(Option C:重载时重新推导闩)是独立设计决策(误报 vs 覆盖的取舍),需 owner 拍板,未塞进本 PR。
  8. 是否引入了新的配置:不涉及。

收工判定:代码与测试正确、CI 绿;但 Closes #7670 会关错 PR(应为 #7669)——这是合并前必须修的阻断项。请 owner 把标题/正文/commit message 里的 #7670 改为 #7669,并把分支更新到当前 master,即可合并。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working p2 scope/kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant